package top.coolrainly.module.resource.dal.mysql.content;

import java.util.*;

import top.coolrainly.framework.common.pojo.PageResult;
import top.coolrainly.framework.mybatis.core.query.LambdaQueryWrapperX;
import top.coolrainly.framework.mybatis.core.mapper.BaseMapperX;
import top.coolrainly.module.resource.dal.dataobject.content.ResourceContentDO;
import org.apache.ibatis.annotations.Mapper;
import top.coolrainly.module.resource.controller.admin.content.vo.*;

/**
 * Web3D 资源 内容 Mapper
 *
 * @author CoolRainLy
 */
@Mapper
public interface ResourceContentMapper extends BaseMapperX<ResourceContentDO> {

    default PageResult<ResourceContentDO> selectPage(ResourceContentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ResourceContentDO>()
                .eqIfPresent(ResourceContentDO::getGroupId, reqVO.getGroupId())
                .likeIfPresent(ResourceContentDO::getName, reqVO.getName())
                .eqIfPresent(ResourceContentDO::getType, reqVO.getType())
                .eqIfPresent(ResourceContentDO::getRemark, reqVO.getRemark())
                .eqIfPresent(ResourceContentDO::getUrl, reqVO.getUrl())
                .betweenIfPresent(ResourceContentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ResourceContentDO::getId));
    }

    default int deleteByGroupId(Long groupId) {
        return delete(ResourceContentDO::getGroupId, groupId);
    }

    default List<ResourceContentDO> selectListByType(Integer type) {
        LambdaQueryWrapperX<ResourceContentDO> queryWrapperX = new LambdaQueryWrapperX<>();
        if (Objects.nonNull(type)) {
            queryWrapperX.eq(ResourceContentDO::getType, type);
        }
        return selectList(queryWrapperX);
    }

}